/**
 * Context Service
 * Defaultly, WIT recommand developers puts user-info, token, global events, i18n, skin, theme in it.
 *
 * @export
 * @class ContextService
 */
export class ContextService {
    // static ins: any = (<any>window);
    // tslint:disable-next-line:variable-name
    public static CurrentContext: Context = {} as Context;

    // tslint:disable-next-line:member-ordering
    public static getContext() {
        return ContextService.CurrentContext;
    }

    /**
     * Context initial method. please set the callback method at bootstrap component for initial.
     *
     * @static
     * @param {Function} callback
     *
     * @memberOf ContextService
     */
    // tslint:disable-next-line:member-ordering
    // tslint:disable-next-line:ban-types
    public static initialContext(callback: Function): void {
        callback(this);
    }

    /**
     * Update ContextService item with pair data-structure.
     *
     * @static
     * @param {...IStringPair[]} pairs
     *
     * @memberOf ContextService
     */
    public static updateContextItem(...pairs: IStringPair[]): void {
        for (const pair of pairs) {
            ContextService.CurrentContext[pair.key] = pair.value;
        }
    }
}

/**
 * Normal key-value build-in type
 *
 * @export
 * @interface IPair
 * @template K
 * @template V
 */
export interface IPair<K, V> {
    key: K;
    value: V;
}

/**
 * Key:String type of IPair
 *
 * @export
 * @interface IStringPair
 * @extends {IPair<string, any>}
 */
export interface IStringPair extends IPair<string, any> {
}

// tslint:disable-next-line:max-classes-per-file
export class Context {
    public token?: string;
    public user?: User;
    public serviceObserver?: any;
    public lang?: string;
    public httpHeaders?: any;
    public pilotStatus?: boolean;
    public platform?: string;
    public config?: any;
    public extend?: any;
}

// tslint:disable-next-line:max-classes-per-file
export class User {
    public name: string;
    public chname: string;
    public enname: string;
}
